<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>宜鲜生</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <!-- load css -->
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css?v=v3.3.7" media="all">
    <link rel="stylesheet" type="text/css" href="../css/font/iconfont.css?v=1.0.0" media="all">
    <link rel="stylesheet" type="text/css" href="../css/layui.css?v=1.0.9" media="all">
    <link rel="stylesheet" type="text/css" href="../css/main.css?v1.3.4" media="all">

</head>
<body>
    <div class="container-fluid larry-wrapper">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <!--头部搜索-->
                <section class="panel panel-padding">
                    <form class="layui-form" action="/education/admin/category">
                        <div class="layui-form">
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="_query.keyword" placeholder="关键字">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button lay-submit class="layui-btn" lay-filter="search">查找</button>
                            </div>
                        </div>
                    </form>
                </section>

                <!--列表-->
                <section class="panel panel-padding">
                    <div class="group-button">

                        <button class="layui-btn layui-btn-small modal-catch"
                                data-params='{"content":".add-subcat", "area":"600px;auto", "title":"添加分类","type":"1","data":"url=/education/admin/category/save"}'>
                            <i class="iconfont">&#xe649;</i> 添加
                        </button>
                        <button class="layui-btn layui-btn-small layui-btn-danger ajax-all" data-name="checkbox"
                                data-params='{"url": "/education/admin/category/delete","data":""}'>
                            <i class="iconfont">&#xe626;</i> 删除
                        </button>
                        <button class="layui-btn layui-btn-small layui-btn-normal ajax-all" data-name="checkbox"
                                data-params='{"url": "/education/admin/top/save", "data": "type=3","confirm":"true"}'>
                            <i class="iconfont">&#xe654;</i> 推送
                        </button>
                        <!--<button class="layui-btn layui-btn-small layui-btn-normal" id="importBtn"
                                data-url='/education/admin/import/category'>
                            <i class="layui-icon">&#xe608;</i>导入
                        </button>-->
                        <!--<button class="layui-btn layui-btn-small layui-btn-normal" id="exportBtn"
                                data-url='/education/admin/export?type=category'>
                            <i class="iconfont">&#xe60a;</i>导出
                        </button>-->
                        <!--<div style="display: none">
                            <input type="file" name="file" class="layui-upload-file" id="importFile">
                        </div>-->
                    </div>
                    <div id="list" class="layui-form"></div>

                    <div class="text-right" id="page"></div>
                </section>
            </div>
        </div>
    </div>

    <div class="add-subcat">
        <form id="form1" class="layui-form layui-form-pane" action="/education/admin/category/save">
            <div class="layui-form-item">
                <label class="layui-form-label">上级</label>
                <div class="layui-input-inline">
                    <input type="hidden" name="parent_id" >
                    <input type="text" name="parentname" class="layui-input" readonly>
                </div>
                <a class="layui-btn" onclick="beforeChoice();">
                    <i class="iconfont">&#xe649;</i> 选择
                </a>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">编号</label>
                <div class="layui-input-block">
                    <input type="text" name="category_no" required jq-verify="required" jq-error="请输入编号"
                           class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-block">
                    <input type="text" name="category_name" required jq-verify="required" jq-error="请输入名称"
                           class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-block">
                    <input type="file" name="file" class="layui-upload-file" id="img">
                    <input type="hidden" name="category_icon"  error-id="img-error">
                   <!-- <p id="img-error" class="error"></p>-->
                </div>
                <div class="layui-input-inline"><div class="imgbox" style="width: 800px;"></div></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-block">
                    <input type="number" name="category_ord" required jq-verify="number" jq-error="排序必须为数字"
                           class="layui-input ">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <select name="category_status">
                        <option value="">请选择</option>
                        <option value="0">停用</option>
                        <option value="1">启用</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" jq-submit jq-filter="submit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>

</body>
<!--#include file="category_list.html"-->
<script type="text/javascript" src="../js/lib/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../js/lib/rest.js"></script>
<script src="../js/layui/layui.js"></script>
<!--#include file="common/version.html"-->
<script type="text/javascript">
    layui.use('user_list');

    var treeIndex;
    function beforeChoice(){
        treeIndex = layer.open({
            type: 2,
            shadeClose: true,
            content: "base-tree.html?url=/education/admin/category/treeData", "title": "选择", "area": ['500px',
                '520px'], "maxmin":"true"
        });
    }

    function afterTreeSelected(item) {
        var $ = layui.jquery;
        $('input[name="parent_id"]').val(item.id);
        $('input[name="parentname"]').val(item.name);
        layer.close(treeIndex);
    }

    function _edit(ids){
        /* var checked = $("input[name=checkbox]:checked");
         if(checked.length != 1){
             layer.msg('请选择一项待修改的数据');
             return;
         }
         var ids = checked.val();*/
        var index = layer.open({
            type: 1,
            title:'编辑',
            area:"600px;auto",
            content: $('.add-subcat')
        });
        //layer.full(index);
        $('#form1').attr('action', '/education/admin/category/update/' + ids);
        restGet('/education/admin/category/view/' + ids, null, $('#form1'), function(rs){
            if(rs.code == 200){
                var str =  '<img src="/education{src}" alt="..." class="img-thumbnail">';
                var imgDiv = $('input[name=category_icon]').parent().next().children('.imgbox');
                imgDiv.append(str.replace('{src}', rs.data.category_icon));
            }
        })
    }

    /*
    下级分类管理
     */
    var category_name;
    function _subManage(ids, name) {
        var title = "【{x}】子类管理 ";
        title = title.replace('{x}', name);
        category_name = name;
        var index = layer.open({
            type: 2,
            content: "category_2.html?parentId="+ ids, "title": title, "area": ['500px', '400px'],
            "maxmin":"true"
        });
        layer.full(index);
    }


    layui.use('upload', function (ex) {
        var box;
        //上传文件设置
        layui.upload({
            elem:'#img',
            url: '/education/api/image/category',
            before: function(input) {
                box = $(input).parent('form').parent('div').parent('.layui-input-block');
                if (box.next('div').length > 0) {
                    box.next('div').html('<div class="imgbox"><p>上传中...</p></div>');
                } else {
                    box.after('<div class="layui-input-block"><div class="imgbox"><p>上传中...</p></div></div>');
                }
            },
            success: function(res) {
                if (res.code == 200) {
                    box.next('div').find('div.imgbox').html('<img src="/education' + res.data[0].url + '" alt="..." class="img-thumbnail">');
                    box.find('input[type=hidden]').val(res.data[0].url);
                    form.check(box.find('input[type=hidden]'));
                } else {
                    box.next('div').find('p').html('上传失败...')
                }
            }
        });

    });

    function strRepeat(str, count) {
        var ret = "";
        for (var i = 0; i < count; i++) {
            ret += str;
        }
        return ret;
    }

    function getLevel(path) {
        return path.split('/').length;
    }
</script>

</html>